<?php

declare(strict_types=1);
/**
 * This file is part of MoChat.
 * @link     https://mo.chat
 * @document https://mochat.wiki
 * @contact  group@mo.chat
 * @license  https://github.com/mochat-cloud/mochat/blob/master/LICENSE
 */

namespace MoChat\ClientNew\Model;

use Hyperf\Database\Model\Concerns\CamelCase;
use Hyperf\Database\Model\SoftDeletes;
use Hyperf\DbConnection\Db;
use MoChat\Framework\Model\AbstractModel;
use Qbhy\HyperfAuth\Authenticatable;

class ClientNew extends AbstractModel
{
    use CamelCase;

    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'client';

    public function getId()
    {
        return $this->getKey();
    }
    public function user(){
        return $this->hasOne(UserBtob::class,'unique_id','unique_id')->where('unique_id','!=',0);
    }

    public static function retrieveById($key): ?Authenticatable
    {
        return self::query()->find($key);
    }

    public  function getLastId()
    {
        return self::query()->orderBy('id','desc')->value('id')?:0;
    }

    public function record(){
        return $this->hasMany(\MoChat\App\Client\Model\ClientFollowRecord::class,'client_id','id');
    }

}
